FWFWebViewFactory

FWFWebViewFactory 类是一个用于创建和管理 FWFWebView 实例的工厂类。它实现了 FlutterPlatformViewFactory 协议,这使得它能够在 Flutter 中创建平台视图。


类声明

@interface FWFWebViewFactory : NSObject <FlutterPlatformViewFactory>
@property(nonatomic, weak) FWFInstanceManager *instanceManager;

- (instancetype)initWithManager:(FWFInstanceManager *)manager;
@end

初始化方法

@implementation FWFWebViewFactory
- (instancetype)initWithManager:(FWFInstanceManager *)manager {
  self = [self init];
  if (self) {
    _instanceManager = manager;
  }
  return self;
}

FlutterPlatformViewFactory 协议方法

createArgsCodec

- (NSObject<FlutterMessageCodec> *)createArgsCodec {
  return [FlutterStandardMessageCodec sharedInstance];
}

createWithFrame:viewIdentifier:arguments: (iOS)

#if TARGET_OS_IOS
- (NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame
                                    viewIdentifier:(int64_t)viewId
                                         arguments:(id _Nullable)args {
  NSNumber *identifier = (NSNumber *)args;
  FWFWebView *webView =
      (FWFWebView *)[self.instanceManager instanceForIdentifier:identifier.longValue];
  webView.frame = frame;
  return webView;
}

createWithViewIdentifier:arguments: (macOS)

#else
- (nonnull NSView *)createWithViewIdentifier:(int64_t)viewId arguments:(nullable id)args {
  NSNumber *identifier = (NSNumber *)args;
  FWFWebView *webView =
      (FWFWebView *)[self.instanceManager instanceForIdentifier:identifier.longValue];
  return webView;
}
#endif

本文作者:Maeiee

本文链接:FWFWebViewFactory

版权声明:如无特别声明,本文即为原创文章,版权归 Maeiee 所有,未经允许不得转载!


喜欢我文章的朋友请随缘打赏,鼓励我创作更多更好的作品!